package hn.cch.spring.aop.proxy.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

public class InvocationHandlerImpl implements InvocationHandler {

    public DynamicProxyApi dynamicProxyApi;

    public InvocationHandlerImpl() {
    }

    public InvocationHandlerImpl(DynamicProxyApi dynamicProxyApi) {
        this.dynamicProxyApi = dynamicProxyApi;
    }

    public DynamicProxyApi getProxyInterface() {
        return dynamicProxyApi;
    }

    public void setProxyInterface(DynamicProxyApi dynamicProxyApi) {
        this.dynamicProxyApi = dynamicProxyApi;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before:" + Arrays.toString(args));
        Object invoke = method.invoke(dynamicProxyApi, args);
        System.out.println("after:" + invoke);
        return invoke;
    }
}
